package com.itheima.controller.pms;

import com.itheima.api.pms.PmsProductAttributeService;
import com.itheima.vo.domain.AjaxResult;
import com.itheima.vo.pojo.PmsProductAttribute;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("productAttribute")
public class PmsProductAttributeController {

    @DubboReference
    private PmsProductAttributeService PmsProductAttributeService;

    /**
     * 1.根据商品分类的id获取商品属性及属性分类
     * @param productCategoryId
     * @return
     */
    @GetMapping("attrInfo/{productCategoryId}")
    public AjaxResult getAttrInfo(@PathVariable(value = "productCategoryId", required = true) Integer productCategoryId) {
        return PmsProductAttributeService.getAttrInfo(productCategoryId);
    }

    /**
     * 2.添加商品属性信息
     * @param pmsProductAttribute
     * @return
     */
    @PostMapping("create")
    public AjaxResult create(@RequestBody PmsProductAttribute pmsProductAttribute) {
        return PmsProductAttributeService.create(pmsProductAttribute);
    }

    /**
     * 3.批量删除商品属性
     * @param ids
     * @return
     */
    @PostMapping("delete")
    public AjaxResult deleteBatch(@RequestParam(value = "ids", required = true) ArrayList<Integer> ids) {
        return PmsProductAttributeService.deleteBatch(ids);
    }

    /**
     * 4.根据分类查询属性列表或参数列表
     * @param cid
     * @param type
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("list/{cid}")
    public AjaxResult getList(@PathVariable(value = "cid", required = true) Integer cid,
                              @RequestParam(value = "type", required = true) Integer type,
                              @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                              @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize) {
        return PmsProductAttributeService.getList(cid,type,pageNum,pageSize);
    }

    /**
     * 5.修改商品属性信息
     * @param id
     * @param pmsProductAttribute
     * @return
     */
    @PostMapping("update/{id}")
    public AjaxResult update(@PathVariable(value = "id", required = true) Integer id,
                             @RequestBody PmsProductAttribute pmsProductAttribute) {
        return PmsProductAttributeService.update(id,pmsProductAttribute);
    }

    /**
     * 6.查询单个商品属性
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public AjaxResult findList(@PathVariable(value = "id", required = true) Integer id) {
        return PmsProductAttributeService.findList(id);
    }
}
